package com.wugui.datax.admin.tool.meta;

/**
 * meta信息interface
 *
 * @author zhouhongfa@gz-yibo.com
 * @ClassName BaseDatabaseMeta
 * @Version 1.0
 * @since 2019/7/17 15:45
 */
public abstract class BaseDatabaseMeta implements DatabaseInterface {

    @Override
    public String getSQLQueryFields(String tableName) {
        return "SELECT * FROM " + tableName + " where 1=0";
    }

    @Override
    public String getSQLQueryTablesNameComments() {
        return "select table_name,table_comment from information_schema.tables where table_schema=(select database())";
    }

    @Override
    public String getSQLQueryTableNameComment() {
        return "select table_name,table_comment from information_schema.tables where table_schema=? and table_name = ?";
    }

    @Override
    public String getSQLQueryPrimaryKey() {
        return null;
    }

    @Override
    public String getSQLQueryComment(String schemaName, String tableName, String columnName) {
        return null;
    }

    @Override
    public String getSQLQueryColumns(String... args) {
        return null;
    }

    @Override
    public String getMaxId(String tableName, String primaryKey) {
        return String.format("select max(%s) from %s",primaryKey,tableName);
    }

    @Override
    public String getSQLQueryTableSchema(String... args) {
        return null;
    }

    @Override
    public String getSQLQueryFields(String database, String tableName) {
        return "select column_name,\n" +
                "\t\t (case when (is_nullable = 'no' &&  column_key != 'PRI') then '1' else null end) as is_required,\n" +
                "\t\t (case when column_key = 'PRI' then '1' else '0' end) as is_pk,\n" +
                "\t\t  ordinal_position as sort,\n" +
                "\t\t  column_comment,\n" +
                "\t\t  (case when extra = 'auto_increment' then '1' else '0' end) as is_increment,\n" +
                "\t\t  column_type,\n" +
                "\t\t  data_type,\n" +
                "\t\t  table_name,\n" +
                "\t\t  character_maximum_length\n" +
                "\t\tfrom information_schema.columns where table_schema = (select database()) and table_name = '"+tableName+"'\n" +
                "\t\torder by ordinal_position";
    }
}
